package ycoa.data.classes

import javax.jdo.annotations.IdGeneratorStrategy
import javax.jdo.annotations.Persistent
import javax.jdo.annotations.PrimaryKey

import groovy.xml.StreamingMarkupBuilder

import java.text.SimpleDateFormat

import groovy.util.XmlSlurper

public class Class {

  @PrimaryKey def key
  def market
  def clID
  def clName
  def clSptype
  def clstartTime
  def clEndTime
  def clActive
  def clWeeks
  def clClassfee
  def clTestFee
  def clRegFee
  def clPHClassFee
  def clSparringFee
  def clPrepaidFee
  def clAdvancePrepaidFee
  def cladvanceFee
  def clReturnPrepaidFee
  def clReturnadvancePrepaidFee
  def clStartDate
  def dWeek2Date
  def clEndDate
  def clReturnStartDate
  def clReturnStartDate1
  def clReturnStartDate2
  def clTestingDate
  def clNextSessionDate
  def clReturnNextSessionDate
  def clNoClassDate1
  def clNoClassDate2
  def clNoClassDate3
  def clNoClassDate4
  def clNoClassDate5
  def clNoClassDate6
  def clNoClassDate7
  def clNoClassDate8
  def clTimeDesc1
  def clTimeDesc2
  def clTimeDesc3
  def clTimeDesc4
  def clTimeDesc5
  def clTimeDesc6
  def clTimeDesc7
  def clTimeDesc8
  def clTimeDesc9
  def clTimeDesc10
  def clYear
  def clSemester
  def clLastModDate
  def clLastModBy
  def clFirstClassType
  def clLastClassType
  def clAdvancedClass
  def clGroup1Name
  def clGroup2Name
  def clGroup3Name
  def clGroup1StartTime
  def clGroup2StartTime
  def clGroup3StartTime
  def clGroup1EndTime
  def clGroup2EndTime
  def clGroup3EndTime
  def clGroup1RegistrationTime
  def clGroup2RegistrationTime
  def clGroup3RegistrationTime
  def clGroup1
  def clGroup2
  def clGroup3
  def clRegistrationTime1
  def clRegistrationTime2
  def clRegistrationTIme3
  def clClassStartTime1
  def clClassStartTime2
  def clClassStartTime3
  def clClassEndTime1
  def clClassEndTime2
  def clClassEndTime3
  def clNoClassDate1Reason
  def clNoClassDate2Reason
  def clNoClassDate3Reason
  def clNoClassDate4Reason
  def clNoClassDate5Reason
  def clNoClassDate6Reason
  def clNoClassDate7Reason
  def clNoClassDate8Reason
  def clExtendedFee
  def clExtendedPrepaidFee
  def lcID
  def lcLocation
  def lcStatus
  def lcType
  def lcKnownAs
  def lcFacilityType1
  def lcFacilityType2
  def lcFacilityType3
  def lcAddress
  def lcAddress2
  def lcCounty
  def lcRegion
  def lcCity
  def lcState
  def lcZip
  def lcSchool_District
  def lcSponsor
  def lcDirections
  def lcLastModBy
  def lclastModDate
  def lcDirectionsSpanish
  def inID
  def inCode
  def inLastName
  def inFirstName
  def inMiddleName
  def inNickName
  def inActive
  def inAddressPrimary1
  def inAddressPrimary2
  def inCityPrimary
  def inStatePrimary
  def inZipPrimary
  def inAddressAlt1
  def inAddressAlt2
  def inCityAlt
  def inStateAlt
  def inZipAlt
  def inEmail
  def inEmailAlt
  def inLastModDate
  def inLastModBy
  def inDoNotEmail
  def inDoNotSolicit

  private ArrayList<String> lex(String line) {
    def tokens = []
    def buffer = new StringBuffer()
    line.each() { character ->
      switch(character) {
        case '\t':
	  tokens << buffer.toString()
	  buffer = new StringBuffer()
	  break
        default:
	  buffer << character
	  break
      }
    }
    return tokens
  }

  private Date parseDate(data) {
    //def dateFormatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    if(data) { 
      return dateFormatter.parse(data)
    } else {
      return null
    }
  }

  private Integer parseInt(data) {
    if(data) { 
      return Integer.parseInt(data)
    } else {
      return null
    }
  }

  private Float parseFloat(data) {
    if(data) { 
      return Float.parseFloat(data)
    } else {
      return null
    }
  }

  private String generatePrimaryKey() {
    key = new String("${market.toUpperCase()}${clID}")
  }

  public String parseXml(node) {
    market                    = node.@market.toString()
    clID                      = parseInt(node.@clID.toString())
    clName                    = node.@clName.toString()
    clSptype                  = node.@clSptype.toString()
    clstartTime               = node.@clstartTime.toString()
    clEndTime                 = node.@clEndTime.toString()
    clActive                  = node.@clActive.toString()
    clWeeks                   = node.@clWeeks.toString()
    clClassfee                = parseFloat(node.@clClassfee.toString())
    clTestFee                 = parseFloat(node.@clTestFee.toString())
    clRegFee                  = parseFloat(node.@clRegFee.toString())
    clPHClassFee              = parseFloat(node.@clPHClassFee.toString())
    clSparringFee             = parseFloat(node.@clSparringFee.toString())
    clPrepaidFee              = parseFloat(node.@clPrepaidFee.toString())
    clAdvancePrepaidFee       = parseFloat(node.@clAdvancePrepaidFee.toString())
    cladvanceFee              = parseFloat(node.@cladvanceFee.toString())
    clReturnPrepaidFee        = parseFloat(node.@clReturnPrepaidFee.toString())
    clReturnadvancePrepaidFee = parseFloat(node.@clReturnadvancePrepaidFee.toString())
    clStartDate               = parseDate(node.@clStartDate.toString())
    dWeek2Date                = parseDate(node.dWeek2Date.toString())
    clEndDate                 = parseDate(node.@clEndDate.toString())
    clReturnStartDate         = parseDate(node.@clReturnStartDate.toString())
    clReturnStartDate1        = parseDate(node.@clReturnStartDate1.toString())
    clReturnStartDate2        = parseDate(node.@clReturnStartDate2.toString())
    clTestingDate             = parseDate(node.@clTestingDate.toString())
    clNextSessionDate         = parseDate(node.@clNextSessionDate.toString())
    clReturnNextSessionDate   = parseDate(node.@clReturnNextSessionDate.toString())
    clNoClassDate1            = parseDate(node.@clNoClassDate1.toString())
    clNoClassDate2            = parseDate(node.@clNoClassDate2.toString())
    clNoClassDate3            = parseDate(node.@clNoClassDate3.toString())
    clNoClassDate4            = parseDate(node.@clNoClassDate4.toString())
    clNoClassDate5            = parseDate(node.@clNoClassDate5.toString())
    clNoClassDate6            = parseDate(node.@clNoClassDate6.toString())
    clNoClassDate7            = parseDate(node.@clNoClassDate7.toString())
    clNoClassDate8            = parseDate(node.@clNoClassDate8.toString())
    clTimeDesc1               = node.@clTimeDesc1.toString()
    clTimeDesc2               = node.@clTimeDesc2.toString()
    clTimeDesc3               = node.@clTimeDesc3.toString()
    clTimeDesc4               = node.@clTimeDesc4.toString()
    clTimeDesc5               = node.@clTimeDesc5.toString()
    clTimeDesc6               = node.@clTimeDesc6.toString()
    clTimeDesc7               = node.@clTimeDesc7.toString()
    clTimeDesc8               = node.@clTimeDesc8.toString()
    clTimeDesc9               = node.@clTimeDesc9.toString()
    clTimeDesc10              = node.@clTimeDesc10.toString()
    clYear                    = parseInt(node.@clYear.toString())
    clSemester                = node.@clSemester.toString()
    clLastModDate             = parseDate(node.@clLastModDate.toString())
    clLastModBy               = node.@clLastModBy.toString()
    clFirstClassType          = parseInt(node.@clFirstClassType.toString())
    clLastClassType           = parseInt(node.@clLastClassType.toString())
    clAdvancedClass           = node.@clAdvancedClass.toString()
    clGroup1Name              = node.@clGroup1Name.toString()
    clGroup2Name              = node.@clGroup2Name.toString()
    clGroup3Name              = node.@clGroup3Name.toString()
    clGroup1StartTime         = node.@clGroup1StartTime.toString()
    clGroup2StartTime         = node.@clGroup2StartTime.toString()
    clGroup3StartTime         = node.@clGroup3StartTime.toString()
    clGroup1EndTime           = node.@clGroup1EndTime.toString()
    clGroup2EndTime           = node.@clGroup2EndTime.toString()
    clGroup3EndTime           = node.@clGroup3EndTime.toString()
    clGroup1RegistrationTime  = node.@clGroup1RegistrationTime.toString()
    clGroup2RegistrationTime  = node.@clGroup2RegistrationTime.toString()
    clGroup3RegistrationTime  = node.@clGroup3RegistrationTime.toString()
    clGroup1                  = node.@clGroup1.toString()
    clGroup2                  = node.@clGroup2.toString()
    clGroup3                  = node.@clGroup3.toString()
    clRegistrationTime1       = node.@clRegistrationTime1.toString()
    clRegistrationTime2       = node.@clRegistrationTime2.toString()
    clRegistrationTIme3       = node.@clRegistrationTIme3.toString()
    clClassStartTime1         = node.@clClassStartTime1.toString()
    clClassStartTime2         = node.@clClassStartTime2.toString()
    clClassStartTime3         = node.@clClassStartTime3.toString()
    clClassEndTime1           = node.@clClassEndTime1.toString()
    clClassEndTime2           = node.@clClassEndTime2.toString()
    clClassEndTime3           = node.@clClassEndTime3.toString()
    clNoClassDate1Reason      = node.@clNoClassDate1Reason.toString()
    clNoClassDate2Reason      = node.@clNoClassDate2Reason.toString()
    clNoClassDate3Reason      = node.@clNoClassDate3Reason.toString()
    clNoClassDate4Reason      = node.@clNoClassDate4Reason.toString()
    clNoClassDate5Reason      = node.@clNoClassDate5Reason.toString()
    clNoClassDate6Reason      = node.@clNoClassDate6Reason.toString()
    clNoClassDate7Reason      = node.@clNoClassDate7Reason.toString()
    clNoClassDate8Reason      = node.@clNoClassDate8Reason.toString()
    clExtendedFee             = parseFloat(node.@clExtendedFee.toString())
    clExtendedPrepaidFee      = parseFloat(node.@clExtendedPrepaidFee.toString())
    lcID                      = parseInt(node.LOCATIONS.@lcID.toString())
    lcLocation                = node.LOCATIONS.@lcLocation.toString()
    lcStatus                  = node.LOCATIONS.@lcStatus.toString()
    lcType                    = node.LOCATIONS.@lcType.toString()
    lcKnownAs                 = node.LOCATIONS.@lcKnownAs.toString()
    lcFacilityType1           = node.LOCATIONS.@lcFacilityType1.toString()
    lcFacilityType2           = node.LOCATIONS.@lcFacilityType2.toString()
    lcFacilityType3           = node.LOCATIONS.@lcFacilityType3.toString()
    lcAddress                 = node.LOCATIONS.@lcAddress.toString()
    lcAddress2                = node.LOCATIONS.@lcAddress2.toString()
    lcCounty                  = node.LOCATIONS.@lcCounty.toString()
    lcRegion                  = node.LOCATIONS.@lcRegion.toString()
    lcCity                    = node.LOCATIONS.@lcCity.toString()
    lcState                   = node.LOCATIONS.@lcState.toString()
    lcZip                     = node.LOCATIONS.@lcZip.toString()
    lcSchool_District         = node.LOCATIONS.@lcSchool_District.toString()
    lcSponsor                 = node.LOCATIONS.@lcSponsor.toString()
    lcDirections              = node.LOCATIONS.@lcDirections.toString()
    lcLastModBy               = node.LOCATIONS.@lcLastModBy.toString()
    lclastModDate             = parseDate(node.LOCATIONS.@lclastModDate.toString())
    lcDirectionsSpanish       = node.LOCATIONS.@lcDirectionsSpanish.toString()
    inID                      = parseInt(node.LOCATIONS.INSTRUCTORS.@inID.toString())
    inCode                    = node.LOCATIONS.INSTRUCTORS.@inCode.toString()
    inLastName                = node.LOCATIONS.INSTRUCTORS.@inLastName.toString()
    inFirstName               = node.LOCATIONS.INSTRUCTORS.@inFirstName.toString()
    inMiddleName              = node.LOCATIONS.INSTRUCTORS.@inMiddleName.toString()
    inNickName                = node.LOCATIONS.INSTRUCTORS.@inNickName.toString()
    inActive                  = node.LOCATIONS.INSTRUCTORS.@inActive.toString()
    inAddressPrimary1         = node.LOCATIONS.INSTRUCTORS.@inAddressPrimary1.toString()
    inAddressPrimary2         = node.LOCATIONS.INSTRUCTORS.@inAddressPrimary2.toString()
    inCityPrimary             = node.LOCATIONS.INSTRUCTORS.@inCityPrimary.toString()
    inStatePrimary            = node.LOCATIONS.INSTRUCTORS.@inStatePrimary.toString()
    inZipPrimary              = node.LOCATIONS.INSTRUCTORS.@inZipPrimary.toString()
    inAddressAlt1             = node.LOCATIONS.INSTRUCTORS.@inAddressAlt1.toString()
    inAddressAlt2             = node.LOCATIONS.INSTRUCTORS.@inAddressAlt2.toString()
    inCityAlt                 = node.LOCATIONS.INSTRUCTORS.@inCityAlt.toString()
    inStateAlt                = node.LOCATIONS.INSTRUCTORS.@inStateAlt.toString()
    inZipAlt                  = node.LOCATIONS.INSTRUCTORS.@inZipAlt.toString()
    inEmail                   = node.LOCATIONS.INSTRUCTORS.@inEmail.toString()
    inEmailAlt                = node.LOCATIONS.INSTRUCTORS.@inEmailAlt.toString()
    inLastModDate             = parseDate(node.LOCATIONS.INSTRUCTORS.@inLastModDate.toString())
    inLastModBy               = node.LOCATIONS.INSTRUCTORS.@inLastModBy.toString()
    inDoNotEmail              = node.LOCATIONS.INSTRUCTORS.@inDoNotEmail.toString()
    inDoNotSolicit            = node.LOCATIONS.INSTRUCTORS.@inDoNotSolicit.toString()
    generatePrimaryKey()
  }

  public String parse(String line) {
    def tokens = lex(line)
    def tokenIndex = 0
    market                    = tokens[tokenIndex++]
    clID                      = parseInt(tokens[tokenIndex++])
    clName                    = tokens[tokenIndex++]
    clSptype                  = tokens[tokenIndex++]
    clstartTime               = tokens[tokenIndex++]
    clEndTime                 = tokens[tokenIndex++]
    clActive                  = tokens[tokenIndex++]
    clWeeks                   = tokens[tokenIndex++]
    clClassfee                = parseFloat(tokens[tokenIndex++])
    clTestFee                 = parseFloat(tokens[tokenIndex++])
    clRegFee                  = parseFloat(tokens[tokenIndex++])
    clPHClassFee              = parseFloat(tokens[tokenIndex++])
    clSparringFee             = parseFloat(tokens[tokenIndex++])
    clPrepaidFee              = parseFloat(tokens[tokenIndex++])
    clAdvancePrepaidFee       = parseFloat(tokens[tokenIndex++])
    cladvanceFee              = parseFloat(tokens[tokenIndex++])
    clReturnPrepaidFee        = parseFloat(tokens[tokenIndex++])
    clReturnadvancePrepaidFee = parseFloat(tokens[tokenIndex++])
    clStartDate               = parseDate(tokens[tokenIndex++])
    dWeek2Date                = parseDate(tokens[tokenIndex++])
    clEndDate                 = parseDate(tokens[tokenIndex++])
    clReturnStartDate         = parseDate(tokens[tokenIndex++])
    clReturnStartDate1        = parseDate(tokens[tokenIndex++])
    clReturnStartDate2        = parseDate(tokens[tokenIndex++])
    clTestingDate             = parseDate(tokens[tokenIndex++])
    clNextSessionDate         = parseDate(tokens[tokenIndex++])
    clReturnNextSessionDate   = parseDate(tokens[tokenIndex++])
    clNoClassDate1            = parseDate(tokens[tokenIndex++])
    clNoClassDate2            = parseDate(tokens[tokenIndex++])
    clNoClassDate3            = parseDate(tokens[tokenIndex++])
    clNoClassDate4            = parseDate(tokens[tokenIndex++])
    clNoClassDate5            = parseDate(tokens[tokenIndex++])
    clNoClassDate6            = parseDate(tokens[tokenIndex++])
    clNoClassDate7            = parseDate(tokens[tokenIndex++])
    clNoClassDate8            = parseDate(tokens[tokenIndex++])
    clTimeDesc1               = tokens[tokenIndex++]
    clTimeDesc2               = tokens[tokenIndex++]
    clTimeDesc3               = tokens[tokenIndex++]
    clTimeDesc4               = tokens[tokenIndex++]
    clTimeDesc5               = tokens[tokenIndex++]
    clTimeDesc6               = tokens[tokenIndex++]
    clTimeDesc7               = tokens[tokenIndex++]
    clTimeDesc8               = tokens[tokenIndex++]
    clTimeDesc9               = tokens[tokenIndex++]
    clTimeDesc10              = tokens[tokenIndex++]
    clYear                    = parseInt(tokens[tokenIndex++])
    clSemester                = tokens[tokenIndex++]
    clLastModDate             = parseDate(tokens[tokenIndex++])
    clLastModBy               = tokens[tokenIndex++]
    clFirstClassType          = parseInt(tokens[tokenIndex++])
    clLastClassType           = parseInt(tokens[tokenIndex++])
    clAdvancedClass           = tokens[tokenIndex++]
    clGroup1Name              = tokens[tokenIndex++]
    clGroup2Name              = tokens[tokenIndex++]
    clGroup3Name              = tokens[tokenIndex++]
    clGroup1StartTime         = tokens[tokenIndex++]
    clGroup2StartTime         = tokens[tokenIndex++]
    clGroup3StartTime         = tokens[tokenIndex++]
    clGroup1EndTime           = tokens[tokenIndex++]
    clGroup2EndTime           = tokens[tokenIndex++]
    clGroup3EndTime           = tokens[tokenIndex++]
    clGroup1RegistrationTime  = tokens[tokenIndex++]
    clGroup2RegistrationTime  = tokens[tokenIndex++]
    clGroup3RegistrationTime  = tokens[tokenIndex++]
    clGroup1                  = tokens[tokenIndex++]
    clGroup2                  = tokens[tokenIndex++]
    clGroup3                  = tokens[tokenIndex++]
    clRegistrationTime1       = tokens[tokenIndex++]
    clRegistrationTime2       = tokens[tokenIndex++]
    clRegistrationTIme3       = tokens[tokenIndex++]
    clClassStartTime1         = tokens[tokenIndex++]
    clClassStartTime2         = tokens[tokenIndex++]
    clClassStartTime3         = tokens[tokenIndex++]
    clClassEndTime1           = tokens[tokenIndex++]
    clClassEndTime2           = tokens[tokenIndex++]
    clClassEndTime3           = tokens[tokenIndex++]
    clNoClassDate1Reason      = tokens[tokenIndex++]
    clNoClassDate2Reason      = tokens[tokenIndex++]
    clNoClassDate3Reason      = tokens[tokenIndex++]
    clNoClassDate4Reason      = tokens[tokenIndex++]
    clNoClassDate5Reason      = tokens[tokenIndex++]
    clNoClassDate6Reason      = tokens[tokenIndex++]
    clNoClassDate7Reason      = tokens[tokenIndex++]
    clNoClassDate8Reason      = tokens[tokenIndex++]
    clExtendedFee             = parseFloat(tokens[tokenIndex++])
    clExtendedPrepaidFee      = parseFloat(tokens[tokenIndex++])
    lcID                      = parseInt(tokens[tokenIndex++])
    lcLocation                = tokens[tokenIndex++]
    lcStatus                  = tokens[tokenIndex++]
    lcType                    = tokens[tokenIndex++]
    lcKnownAs                 = tokens[tokenIndex++]
    lcFacilityType1           = tokens[tokenIndex++]
    lcFacilityType2           = tokens[tokenIndex++]
    lcFacilityType3           = tokens[tokenIndex++]
    lcAddress                 = tokens[tokenIndex++]
    lcAddress2                = tokens[tokenIndex++]
    lcCounty                  = tokens[tokenIndex++]
    lcRegion                  = tokens[tokenIndex++]
    lcCity                    = tokens[tokenIndex++]
    lcState                   = tokens[tokenIndex++]
    lcZip                     = tokens[tokenIndex++]
    lcSchool_District         = tokens[tokenIndex++]
    lcSponsor                 = tokens[tokenIndex++]
    lcDirections              = tokens[tokenIndex++]
    lcLastModBy               = tokens[tokenIndex++]
    lclastModDate             = parseDate(tokens[tokenIndex++])
    lcDirectionsSpanish       = tokens[tokenIndex++]
    inID                      = parseInt(tokens[tokenIndex++])
    inCode                    = tokens[tokenIndex++]
    inLastName                = tokens[tokenIndex++]
    inFirstName               = tokens[tokenIndex++]
    inMiddleName              = tokens[tokenIndex++]
    inNickName                = tokens[tokenIndex++]
    inActive                  = tokens[tokenIndex++]
    inAddressPrimary1         = tokens[tokenIndex++]
    inAddressPrimary2         = tokens[tokenIndex++]
    inCityPrimary             = tokens[tokenIndex++]
    inStatePrimary            = tokens[tokenIndex++]
    inZipPrimary              = tokens[tokenIndex++]
    inAddressAlt1             = tokens[tokenIndex++]
    inAddressAlt2             = tokens[tokenIndex++]
    inCityAlt                 = tokens[tokenIndex++]
    inStateAlt                = tokens[tokenIndex++]
    inZipAlt                  = tokens[tokenIndex++]
    inEmail                   = tokens[tokenIndex++]
    inEmailAlt                = tokens[tokenIndex++]
    inLastModDate             = parseDate(tokens[tokenIndex++])
    inLastModBy               = tokens[tokenIndex++]
    inDoNotEmail              = tokens[tokenIndex++]
    inDoNotSolicit            = tokens[tokenIndex++]
    generatePrimaryKey()
  }

  public String toString() {
    def sb = new StringBuffer()
    sb << "key := ${key}" << "\n"
    sb << "market := ${market}" << "\n"
    sb << "clID := ${clID}" << "\n"
    sb << "clName := ${clName}" << "\n"
    sb << "clSptype := ${clSptype}" << "\n"
    sb << "clstartTime := ${clstartTime}" << "\n"
    sb << "clEndTime := ${clEndTime}" << "\n"
    sb << "clActive := ${clActive}" << "\n"
    sb << "clWeeks := ${clWeeks}" << "\n"
    sb << "clClassfee := ${clClassfee}" << "\n"
    sb << "clTestFee := ${clTestFee}" << "\n"
    sb << "clRegFee := ${clRegFee}" << "\n"
    sb << "clPHClassFee := ${clPHClassFee}" << "\n"
    sb << "clSparringFee := ${clSparringFee}" << "\n"
    sb << "clPrepaidFee := ${clPrepaidFee}" << "\n"
    sb << "clAdvancePrepaidFee := ${clAdvancePrepaidFee}" << "\n"
    sb << "cladvanceFee := ${cladvanceFee}" << "\n"
    sb << "clReturnPrepaidFee := ${clReturnPrepaidFee}" << "\n"
    sb << "clReturnadvancePrepaidFee := ${clReturnadvancePrepaidFee}" << "\n"
    sb << "clStartDate := ${clStartDate}" << "\n"
    sb << "dWeek2Date := ${dWeek2Date}" << "\n"
    sb << "clEndDate := ${clEndDate}" << "\n"
    sb << "clReturnStartDate := ${clReturnStartDate}" << "\n"
    sb << "clReturnStartDate1 := ${clReturnStartDate1}" << "\n"
    sb << "clReturnStartDate2 := ${clReturnStartDate2}" << "\n"
    sb << "clTestingDate := ${clTestingDate}" << "\n"
    sb << "clNextSessionDate := ${clNextSessionDate}" << "\n"
    sb << "clReturnNextSessionDate := ${clReturnNextSessionDate}" << "\n"
    sb << "clNoClassDate1 := ${clNoClassDate1}" << "\n"
    sb << "clNoClassDate2 := ${clNoClassDate2}" << "\n"
    sb << "clNoClassDate3 := ${clNoClassDate3}" << "\n"
    sb << "clNoClassDate4 := ${clNoClassDate4}" << "\n"
    sb << "clNoClassDate5 := ${clNoClassDate5}" << "\n"
    sb << "clNoClassDate6 := ${clNoClassDate6}" << "\n"
    sb << "clNoClassDate7 := ${clNoClassDate7}" << "\n"
    sb << "clNoClassDate8 := ${clNoClassDate8}" << "\n"
    sb << "clTimeDesc1 := ${clTimeDesc1}" << "\n"
    sb << "clTimeDesc2 := ${clTimeDesc2}" << "\n"
    sb << "clTimeDesc3 := ${clTimeDesc3}" << "\n"
    sb << "clTimeDesc4 := ${clTimeDesc4}" << "\n"
    sb << "clTimeDesc5 := ${clTimeDesc5}" << "\n"
    sb << "clTimeDesc6 := ${clTimeDesc6}" << "\n"
    sb << "clTimeDesc7 := ${clTimeDesc7}" << "\n"
    sb << "clTimeDesc8 := ${clTimeDesc8}" << "\n"
    sb << "clTimeDesc9 := ${clTimeDesc9}" << "\n"
    sb << "clTimeDesc10 := ${clTimeDesc10}" << "\n"
    sb << "clYear := ${clYear}" << "\n"
    sb << "clSemester := ${clSemester}" << "\n"
    sb << "clLastModDate := ${clLastModDate}" << "\n"
    sb << "clLastModBy := ${clLastModBy}" << "\n"
    sb << "clFirstClassType := ${clFirstClassType}" << "\n"
    sb << "clLastClassType := ${clLastClassType}" << "\n"
    sb << "clAdvancedClass := ${clAdvancedClass}" << "\n"
    sb << "clGroup1Name := ${clGroup1Name}" << "\n"
    sb << "clGroup2Name := ${clGroup2Name}" << "\n"
    sb << "clGroup3Name := ${clGroup3Name}" << "\n"
    sb << "clGroup1StartTime := ${clGroup1StartTime}" << "\n"
    sb << "clGroup2StartTime := ${clGroup2StartTime}" << "\n"
    sb << "clGroup3StartTime := ${clGroup3StartTime}" << "\n"
    sb << "clGroup1EndTime := ${clGroup1EndTime}" << "\n"
    sb << "clGroup2EndTime := ${clGroup2EndTime}" << "\n"
    sb << "clGroup3EndTime := ${clGroup3EndTime}" << "\n"
    sb << "clGroup1RegistrationTime := ${clGroup1RegistrationTime}" << "\n"
    sb << "clGroup2RegistrationTime := ${clGroup2RegistrationTime}" << "\n"
    sb << "clGroup3RegistrationTime := ${clGroup3RegistrationTime}" << "\n"
    sb << "clGroup1 := ${clGroup1}" << "\n"
    sb << "clGroup2 := ${clGroup2}" << "\n"
    sb << "clGroup3 := ${clGroup3}" << "\n"
    sb << "clRegistrationTime1 := ${clRegistrationTime1}" << "\n"
    sb << "clRegistrationTime2 := ${clRegistrationTime2}" << "\n"
    sb << "clRegistrationTIme3 := ${clRegistrationTIme3}" << "\n"
    sb << "clClassStartTime1 := ${clClassStartTime1}" << "\n"
    sb << "clClassStartTime2 := ${clClassStartTime2}" << "\n"
    sb << "clClassStartTime3 := ${clClassStartTime3}" << "\n"
    sb << "clClassEndTime1 := ${clClassEndTime1}" << "\n"
    sb << "clClassEndTime2 := ${clClassEndTime2}" << "\n"
    sb << "clClassEndTime3 := ${clClassEndTime3}" << "\n"
    sb << "clNoClassDate1Reason := ${clNoClassDate1Reason}" << "\n"
    sb << "clNoClassDate2Reason := ${clNoClassDate2Reason}" << "\n"
    sb << "clNoClassDate3Reason := ${clNoClassDate3Reason}" << "\n"
    sb << "clNoClassDate4Reason := ${clNoClassDate4Reason}" << "\n"
    sb << "clNoClassDate5Reason := ${clNoClassDate5Reason}" << "\n"
    sb << "clNoClassDate6Reason := ${clNoClassDate6Reason}" << "\n"
    sb << "clNoClassDate7Reason := ${clNoClassDate7Reason}" << "\n"
    sb << "clNoClassDate8Reason := ${clNoClassDate8Reason}" << "\n"
    sb << "clExtendedFee := ${clExtendedFee}" << "\n"
    sb << "clExtendedPrepaidFee := ${clExtendedPrepaidFee}" << "\n"
    sb << "lcID := ${lcID}" << "\n"
    sb << "lcLocation := ${lcLocation}" << "\n"
    sb << "lcStatus := ${lcStatus}" << "\n"
    sb << "lcType := ${lcType}" << "\n"
    sb << "lcKnownAs := ${lcKnownAs}" << "\n"
    sb << "lcFacilityType1 := ${lcFacilityType1}" << "\n"
    sb << "lcFacilityType2 := ${lcFacilityType2}" << "\n"
    sb << "lcFacilityType3 := ${lcFacilityType3}" << "\n"
    sb << "lcAddress := ${lcAddress}" << "\n"
    sb << "lcAddress2 := ${lcAddress2}" << "\n"
    sb << "lcCounty := ${lcCounty}" << "\n"
    sb << "lcRegion := ${lcRegion}" << "\n"
    sb << "lcCity := ${lcCity}" << "\n"
    sb << "lcState := ${lcState}" << "\n"
    sb << "lcZip := ${lcZip}" << "\n"
    sb << "lcSchool_District := ${lcSchool_District}" << "\n"
    sb << "lcSponsor := ${lcSponsor}" << "\n"
    sb << "lcDirections := ${lcDirections}" << "\n"
    sb << "lcLastModBy := ${lcLastModBy}" << "\n"
    sb << "lclastModDate := ${lclastModDate}" << "\n"
    sb << "lcDirectionsSpanish := ${lcDirectionsSpanish}" << "\n"
    sb << "inID := ${inID}" << "\n"
    sb << "inCode := ${inCode}" << "\n"
    sb << "inLastName := ${inLastName}" << "\n"
    sb << "inFirstName := ${inFirstName}" << "\n"
    sb << "inMiddleName := ${inMiddleName}" << "\n"
    sb << "inNickName := ${inNickName}" << "\n"
    sb << "inActive := ${inActive}" << "\n"
    sb << "inAddressPrimary1 := ${inAddressPrimary1}" << "\n"
    sb << "inAddressPrimary2 := ${inAddressPrimary2}" << "\n"
    sb << "inCityPrimary := ${inCityPrimary}" << "\n"
    sb << "inStatePrimary := ${inStatePrimary}" << "\n"
    sb << "inZipPrimary := ${inZipPrimary}" << "\n"
    sb << "inAddressAlt1 := ${inAddressAlt1}" << "\n"
    sb << "inAddressAlt2 := ${inAddressAlt2}" << "\n"
    sb << "inCityAlt := ${inCityAlt}" << "\n"
    sb << "inStateAlt := ${inStateAlt}" << "\n"
    sb << "inZipAlt := ${inZipAlt}" << "\n"
    sb << "inEmail := ${inEmail}" << "\n"
    sb << "inEmailAlt := ${inEmailAlt}" << "\n"
    sb << "inLastModDate := ${inLastModDate}" << "\n"
    sb << "inLastModBy := ${inLastModBy}" << "\n"
    sb << "inDoNotEmail := ${inDoNotEmail}" << "\n"
    sb << "inDoNotSolicit := ${inDoNotSolicit}" << "\n"
    return sb.toString()
  }

  public String toXmlString() {
    def sb = new StringBuffer()
    sb << """
      <CLASS 
             key="${key}"
             market="${market}"
             clID="${clID}"
             clName="${clName}"
             clSptype="${clSptype}"
             clstartTime="${clstartTime}"
             clEndTime="${clEndTime}"
             clActive="${clActive}"
             clWeeks="${clWeeks}"
             clClassfee="${clClassfee}"
             clTestFee="${clTestFee}"
             clRegFee="${clRegFee}"
             clPHClassFee="${clPHClassFee}"
             clSparringFee="${clSparringFee}"
             clPrepaidFee="${clPrepaidFee}"
             clAdvancePrepaidFee="${clAdvancePrepaidFee}"
             cladvanceFee="${cladvanceFee}"
             clReturnPrepaidFee="${clReturnPrepaidFee}"
             clReturnadvancePrepaidFee="${clReturnadvancePrepaidFee}"
             clStartDate="${xmlEncodeDate(clStartDate)}"
             dWeek2Date="${xmlEncodeDate(dWeek2Date)}"
             clEndDate="${xmlEncodeDate(clEndDate)}"
             clReturnStartDate="${xmlEncodeDate(clReturnStartDate)}"
             clReturnStartDate1="${xmlEncodeDate(clReturnStartDate1)}"
             clReturnStartDate2="${xmlEncodeDate(clReturnStartDate2)}"
             clTestingDate="${xmlEncodeDate(clTestingDate)}"
             clNextSessionDate="${xmlEncodeDate(clNextSessionDate)}"
             clReturnNextSessionDate="${xmlEncodeDate(clReturnNextSessionDate)}"
             clNoClassDate1="${xmlEncodeDate(clNoClassDate1)}"
             clNoClassDate2="${xmlEncodeDate(clNoClassDate2)}"
             clNoClassDate3="${xmlEncodeDate(clNoClassDate3)}"
             clNoClassDate4="${xmlEncodeDate(clNoClassDate4)}"
             clNoClassDate5="${xmlEncodeDate(clNoClassDate5)}"
             clNoClassDate6="${xmlEncodeDate(clNoClassDate6)}"
             clNoClassDate7="${xmlEncodeDate(clNoClassDate7)}"
             clNoClassDate8="${xmlEncodeDate(clNoClassDate8)}"
             clTimeDesc1="${xmlEncode(clTimeDesc1)}"
             clTimeDesc2="${xmlEncode(clTimeDesc2)}"
             clTimeDesc3="${xmlEncode(clTimeDesc3)}"
             clTimeDesc4="${xmlEncode(clTimeDesc4)}"
             clTimeDesc5="${xmlEncode(clTimeDesc5)}"
             clTimeDesc6="${xmlEncode(clTimeDesc6)}"
             clTimeDesc7="${xmlEncode(clTimeDesc7)}"
             clTimeDesc8="${xmlEncode(clTimeDesc8)}"
             clTimeDesc9="${xmlEncode(clTimeDesc9)}"
             clTimeDesc10="${xmlEncode(clTimeDesc10)}"
             clYear="${clYear}"
             clSemester="${clSemester}"
             clLastModDate="${xmlEncodeDate(clLastModDate)})"
             clLastModBy="${clLastModBy}"
             clFirstClassType="${clFirstClassType}"
             clLastClassType="${clLastClassType}"
             clAdvancedClass="${clAdvancedClass}"
             clGroup1Name="${xmlEncode(clGroup1Name)}"
             clGroup2Name="${xmlEncode(clGroup2Name)}"
             clGroup3Name="${xmlEncode(clGroup3Name)}"
             clGroup1StartTime="${clGroup1StartTime}"
             clGroup2StartTime="${clGroup2StartTime}"
             clGroup3StartTime="${clGroup3StartTime}"
             clGroup1EndTime="${clGroup1EndTime}"
             clGroup2EndTime="${clGroup2EndTime}"
             clGroup3EndTime="${clGroup3EndTime}"
             clGroup1RegistrationTime="${clGroup1RegistrationTime}"
             clGroup2RegistrationTime="${clGroup2RegistrationTime}"
             clGroup3RegistrationTime="${clGroup3RegistrationTime}"
             clGroup1="${xmlEncode(clGroup1)}"
             clGroup2="${xmlEncode(clGroup2)}"
             clGroup3="${xmlEncode(clGroup3)}"
             clRegistrationTime1="${clRegistrationTime1}"
             clRegistrationTime2="${clRegistrationTime2}"
             clRegistrationTIme3="${clRegistrationTIme3}"
             clClassStartTime1="${clClassStartTime1}"
             clClassStartTime2="${clClassStartTime2}"
             clClassStartTime3="${clClassStartTime3}"
             clClassEndTime1="${clClassEndTime1}"
             clClassEndTime2="${clClassEndTime2}"
             clClassEndTime3="${clClassEndTime3}"
             clNoClassDate1Reason="${clNoClassDate1Reason}"
             clNoClassDate2Reason="${clNoClassDate2Reason}"
             clNoClassDate3Reason="${clNoClassDate3Reason}"
             clNoClassDate4Reason="${clNoClassDate4Reason}"
             clNoClassDate5Reason="${clNoClassDate5Reason}"
             clNoClassDate6Reason="${clNoClassDate6Reason}"
             clNoClassDate7Reason="${clNoClassDate7Reason}"
             clNoClassDate8Reason="${clNoClassDate8Reason}"
             clExtendedFee="${clExtendedFee}"
             clExtendedPrepaidFee="${clExtendedPrepaidFee}"
            >
             <LOCATIONS
               lcID="${lcID}"
               lcLocation="${xmlEncode(lcLocation)}"
               lcStatus="${lcStatus}"
               lcType="${lcType}"
               lcKnownAs="${xmlEncode(lcKnownAs)}"
               lcFacilityType1="${lcFacilityType1}"
               lcFacilityType2="${lcFacilityType2}"
               lcFacilityType3="${lcFacilityType3}"
               lcAddress="${xmlEncode(lcAddress)}"
               lcAddress2="${xmlEncode(lcAddress2)}"
               lcCounty="${lcCounty}"
               lcRegion="${lcRegion}"
               lcCity="${lcCity}"
               lcState="${lcState}"
               lcZip="${lcZip}"
               lcSchool_District="${lcSchool_District}"
               lcSponsor="${xmlEncode(lcSponsor)}"
               lcDirections="${xmlEncode(lcDirections)}"
               lcLastModBy="${lcLastModBy}"
               lclastModDate="${xmlEncodeDate(lclastModDate)}"
               lcDirectionsSpanish="${xmlEncode(lcDirectionsSpanish)}"
             />
             <INSTRUCTORS
               inID="${inID}"
               inCode="${inCode}"
               inLastName="${inLastName}"
               inFirstName="${inFirstName}"
               inMiddleName="${inMiddleName}"
               inNickName="${inNickName}"
               inActive="${inActive}"
               inAddressPrimary1="${inAddressPrimary1}"
               inAddressPrimary2="${inAddressPrimary2}"
               inCityPrimary="${inCityPrimary}"
               inStatePrimary="${inStatePrimary}"
               inZipPrimary="${inZipPrimary}"
               inAddressAlt1="${inAddressAlt1}"
               inAddressAlt2="${inAddressAlt2}"
               inCityAlt="${inCityAlt}"
               inStateAlt="${inStateAlt}"
               inZipAlt="${inZipAlt}"
               inEmail="${inEmail}"
               inEmailAlt="${inEmailAlt}"
               inLastModDate="${xmlEncodeDate(inLastModDate)}"
               inLastModBy="${inLastModBy}"
               inDoNotEmail="${inDoNotEmail}"
               inDoNotSolicit="${inDoNotSolicit}"
             />
           </CLASS>
    """
    return sb.toString()
  }

  public String toXml() {
    def xml = new XmlSlurper().parseText("<root>${toXml()}</root>")
  }

  public void loadDefaults() {
  }

  public static main(args) {
    def c = new Class()
    c.loadDefaults()
    println c
  }

  private String xmlEncode(String data) {
    return data.replaceAll("&", "&amp;")
    return data.replaceAll("<", "&lt;")
    return data.replaceAll(">", "&gt;")
  }

  private String xmlEncodeDate(data) {
    def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    if(data) { 
      return dateFormatter.format(data)
    } else {
      return null
    }
  }

}

